class Church < ActiveRecord::Base
  has_many :people
  
  validates :name, :presence => true
  validates :address, :presence => true
  validates :city, :presence => true
  validates :state, :presence => true
  validates :zip_code, :presence => true
  validates_uniqueness_of :name, :scope => :address
  
  paginates_per 10
  
  def self.recent
    where("created_at >= ?", 1.month.ago)
  end
  
  def self.search(search)
    if search
      where('name LIKE ?', "%#{search}%")
    else
      scoped
    end
  end
end
